function [  ] = setZRowName( this, zRowId, zRowName )
% DataMatrix::setZRowName(dataMatrix, zRowId, zRowName)
% Set row names of the DataMatrix object
% 
% Input
% 1. dataMatrix
% 2. zRowId
% 3. zRowName
% 
% Output
% 0. 
% 
% Syntax
% ~. dateMatrix.setZRowName();
% ~. dataMatrix.setZRowName(zRowId);
% ~. dataMatrix.setZRowName(zRowId, zRowName);
% 
% Example
% 1. dataMatrix.setZRowName(); % Set all row names to be {''}s
% 2. dataMatrix.setZRowName(1:2); % Set names of row 1:2 to be {''}s
% 3. dataMatrix.setZRowName(1:2, {'r1', 'r2'});
% 4. dataMatrix.setZRowName(:, {'r'}); % Set all row names to be {'r_#'}s

%% Check input

if nargin == 1 % If >> dataMatrix.setZRowName()
    this.setZRowName(':', {''});
    return
end

if nargin == 2 % If >> dataMatrix.setZRowName(zRowId)
    if isnumeric(zRowId)
        this.setZRowName(zRowId, {''});
    elseif ischar(zRowId{1})
        zRowName = zRowId;
        this.setZRowName(':', zRowName);
    end
    return
end

if nargin == 3
    if isequal(zRowName, {''})
        if isequal(zRowId, ':')
            nRowName = this.nRow;
        else
            nRowName = length(zRowId);
        end
        zRowName = repmat({''}, nRowName, 1);
    else%if ~isequal(zRowName, {''})
        if length(zRowName) == 1 ...
                && (length(zRowId) > 1 || isequal(zRowId, ':'))
            % Generate sequential col names, i.e., {'baseName+#'}s
            % E.g., {'r_1', 'r_2', ... , 'r_n'}
            zRowName = this.genSeqZRowName(zRowName{1}, zRowId);
        end
    end
end

%% Assign

if isequal(zRowId, ':')
    assert(length(zRowName) == this.nRow, ...
        'BatErr: Length dismatch: length(zRowName) MUST equal $.nRow$.');
    zRowId = 1:this.nRow;
else
    assert(length(zRowName) == length(zRowId), ...
        ['BatErr: Length dismatch: ', ...
        'length(zRowName) MUST equal length(zRowId).']);
end

this.zRowName(1, zRowId) = zRowName; % Assignment with auto expanding

% Trim the redundant tailing row names
if length(this.zRowName) > this.nRow
    this.zRowName = this.zRowName(1:this.nRow);
end

end
